<script type="text/javascript">
  $j(function() { 
      
    // チェックボックスをクリックすると既読未読が変更される
    $j('.addStateButton')
    .click( function(){
        changeAddState(this, this.checked);
    });

    var changeAddState = function(checkBoxObj, isRead){
        itemId = checkBoxObj.id.split('_')[1];
        var addedColor = "rgb(255, 255, 170)";
        var notAddedColor = "rgb(255, 255, 255)";

        var newColor = notAddedColor;
        var box = $j('#occasionItemBox_' + itemId);
      
        if(box.css('backgroundColor') == addedColor){
          newColor = notAddedColor;
          newMessage = "候補に追加する";
        }else{
          newColor = addedColor;
          newMessage = "取り消す";
          $j.ajax({
            url: "<%= url_for(:controller => 'occasion_edit', :action => 'create_behind') -%>",
            data: createPostData(itemId),
            complete: function(request) {
            }
          });
        }

        box.css('backgroundColor', newColor);
        $j('#addStateButton_' + itemId).attr('value', newMessage);

     };
     var createPostData = function(itemId){
        var item = $j('#item_' + itemId);
        return "entry_type=OCCASION_BBS&publication_type=private&publication_symbols_value=" +
          "&title=" + item.attr('name') + 
          //"&url=" + item.attr('url') + 
          "&contents=" + item.attr('copy') + "\n\n" + item.attr('url')  + 
          "&symbol=oid%3A<%=@occasion.oid%>";
     };

  });
</script>
<style>
  td span {font-weight: bold;}
</style>
<div class="search_cond_space">
<% form_tag({:action => 'index'}, :method => 'get') do -%>
<table class="search_cond_box">
  <tr>
    <th>氏名</th>
    <td><%= text_field :condition, :name , :size => 25 %></td>
  </tr>
  <tr>
    <th>どんな感じ</th>
    <td><%= select :condition, :sort_type, UserSearchCondition.sort_types -%></td>
  </tr>
</table>
<%= link_to "戻る", "/occasion/"+@occasion.oid %>


<div class="submit"><%= submit_tag '検索' %></div>
<% end %>
</div>

<div style="display:none;" id="no_visible_data_block">
<% row_num = 0 %>
<% for occasion_item in @occasion_items %>
  <% row_num += 1 %>
  <item id="item_<%=row_num%>"
    name="<%=occasion_item.name%>"
    url="<%=occasion_item.url%>"
    copy="<%=occasion_item.copy%>" />
<% end %>
</div>
<div class="search_result_space">

<% row_num = 0 %>
<% for occasion_item in @occasion_items %>
  <% row_num += 1 %>
  <table class="occasion_items_box" border="1" id="occasionItemBox_<%= row_num %>">
  <tr>
    <td width="130x">[Amazon の商品]</td>
    <td><span id="occasionItemTitle_<%=row_num%>"><%= link_to occasion_item.name, occasion_item.url %></span></td>
  </tr>
  <tr>
    <td>
    <% unless occasion_item.selected %> 
      <input type="button" value="候補に追加する" id="addStateButton_<%=row_num%>" class="addStateButton"/> <br />
    <% else %>
      [追加済み]
    <% end %>
    </td>
    <td class="image" width="110px" height="110px" valign="top">
      <%= image_tag occasion_item.thumb ? occasion_item.thumb : "/images/no-images.gif", :width => "100px"%>
      <%=h occasion_item.copy %>
    </td>
  </tr>
</table>

<% end %>


<%= link_to 'New occasion_item', new_occasion_item_path %>
